package one.stand.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.model.ShareRecordModel;
import one.stand.request.*;
import one.stand.response.*;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@RequestMapping("crmApi/company")
@RestController
@Api(description = "企业模块",tags="企业模块")
@Slf4j
public class CompanyController extends BaseController {

    @ApiOperation(value = "添加企业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyLogo", value = "企业logo", paramType = "String"),
            @ApiImplicitParam(name = "companyName", value = "企业名", required = true, paramType = "String"),
            @ApiImplicitParam(name = "industryId", value = "行业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "companyNotice", value = "企业公告", paramType = "String"),
            @ApiImplicitParam(name = "password", value = "企业口令", paramType = "String"),
            @ApiImplicitParam(name = "agentCompanyId", value = "企业的代理商ID", paramType = "Integer"),
    })
    @ApiController(isLogin = true,paramClass = CompanyRequest.class)
    @PostMapping("addCompany")
    public ResultModel<Boolean> addCompany(@RequestAttribute CompanyRequest request) {

        return crmFegin.addCompany(request);
    }

    @ApiOperation(value = "个人企业信息")
    @ApiController(isLogin = true,company = true,isParam = false)
    @PostMapping("getCompany")
    public ResultModel<CompanyResponse> getCompany(CompanyRequest request, @RequestAttribute TokenRequest tokenRequest) {
        BeanUtils.copyProperties(tokenRequest, request);
        return crmFegin.getCompany(request);
    }

    @ApiOperation(value = "查询公司信息(中转)")
    @ApiController(isLogin = true, paramClass = CompanyRequest.class)
    @PostMapping("getCompanyTransfer")
    public ResultModel<CompanyResponse> getCompanyTransfer(@RequestAttribute CompanyRequest request) {

        return crmFegin.getCompany(request);
    }

    @ApiOperation(value = "得到登录人的公司id")
    @ApiController(isLogin = true,paramClass = CompanyRequest.class)
    @PostMapping("getCompanyId")
    public ResultModel<CompanyResponse> getCompanyId(@RequestAttribute CompanyRequest request) {

        return crmFegin.getCompanyId(request);
    }

    @PostMapping("getCompanyAllInfo")
    @ApiOperation(value = "查询公司信息(用于下拉列表查询)")
    @ApiController(isLogin = true,paramClass = CompanyRequest.class)
    @ApiImplicitParam(name = "companyName", value = "公司名称", paramType = "String")
    public ResultModel getCompanyAllInfo(@RequestAttribute CompanyRequest request) {
        return crmFegin.getCompanyAllInfo(request);
    }

    @ApiOperation(value = "企业邀请")
    @ApiImplicitParam(name = "companyId", value = "企业id", paramType = "String")
    @PostMapping("invitation")
    @ApiController(isParam = false)
    public ResultModel<CompanyResponse> invitation(CompanyRequest request) {

        return crmFegin.invitation(request);
    }

    @ApiOperation(value = "修改企业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyLogo", value = "企业logo", required = true, paramType = "String"),
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "String"),
            @ApiImplicitParam(name = "companyName", value = "企业名", required = true, paramType = "String"),
            @ApiImplicitParam(name = "industryId", value = "行业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "companyNotice", value = "企业公告", paramType = "String"),
            @ApiImplicitParam(name = "password", value = "企业口令", paramType = "String"),
    })
    @ApiController(isLogin = true, company = true,isBoss = true,paramClass = CompanyRequest.class)
    @PostMapping("updCompany")
    public ResultModel<Boolean> updCompany(@RequestAttribute CompanyRequest request) {

        return crmFegin.updCompany(request);
    }

    @PostMapping("selectDynamicInfo")
    @ApiOperation(value = "查询公司动态/文章")
    @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer")
    @ApiController(isLogin = true,company=true,paramClass = DynamicRequest.class)
    public ResultModel<List<DynamicResponse>> selectDynamicInfo(@RequestAttribute DynamicRequest request) {

        return crmFegin.selectDynamicInfo(request);
    }

    @PostMapping("getDynamicDetail")
    @ApiOperation(value = "查询公司动态/文章详情")
    @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer")
    @ApiController(isLogin = true,company=true,paramClass = DynamicRequest.class)
    public ResultModel getDynamicDetail(@RequestAttribute DynamicRequest request){
        return crmFegin.getDynamicDetail(request);
    }

    @PostMapping("/selectComment")
    @ApiOperation(value = "查询所有评论/回复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "动态/文章id", required = true, paramType = "Integer")
    })
    @ApiController(isLogin = true,paramClass = CommentRequest.class)
    public ResultModel selectComment(@RequestAttribute CommentRequest request) {

        return crmFegin.selectComment(request);
    }

    @PostMapping("getDynamicInfo")
    @ApiOperation(value = "查询公司动态/文章详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "动态/文章id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,paramClass = DynamicRequest.class)
    public ResultModel<List<DynamicResponse>> getDynamicInfo(@RequestAttribute DynamicRequest request) {

        return crmFegin.getDynamicInfo(request);
    }

    @PostMapping("addDynamicInfo")
    @ApiOperation(value = "添加/修改公司动态/文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "title", value = "标题", required = true, paramType = "String"),
            @ApiImplicitParam(name = "type", value = "类型 1:文章 2:动态 3:转载", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "photos", value = "图片", paramType = "String"),
            @ApiImplicitParam(name = "details", value = "详情", paramType = "String"),
            @ApiImplicitParam(name = "author", value = "当前作者", paramType = "String"),
            @ApiImplicitParam(name = "originAuthor", value = "原始作者，如转载文章的来源公众号", paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = DynamicRequest.class)
    public ResultModel addDynamicInfo(@RequestAttribute DynamicRequest request) {

        return crmFegin.addDynamicInfo(request);
    }



    @PostMapping("resolverDynamic")
    @ApiOperation(value = "解析公众号文章")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "details", value = "详情", paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = DynamicRequest.class)
    public ResultModel resolverDynamic(@RequestAttribute DynamicRequest request) {
        return crmFegin.resolverDynamic(request);
    }


    @PostMapping("/doComment")
    @ApiOperation(value = "crm回复评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "动态/文章id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "parentId", value = "父级ID（评论为0，回复为对应评论ID）", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "text", value = "内容", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,paramClass = CommentRequest.class)
    public ResultModel doComment(@RequestAttribute CommentRequest request) {
        return crmFegin.doComment(request);
    }

    @PostMapping("/delComment")
    @ApiOperation(value = "crm删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论表ID", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,paramClass = CompanyRequest.class)
    public ResultModel delComment(@RequestAttribute CommentRequest request) {
        return crmFegin.delComment(request);
    }

    @PostMapping("delDynamicInfo")
    @ApiOperation(value = "删除公司动态/文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "文章、动态ID", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = DynamicRequest.class)
    public ResultModel delDynamicInfo(@RequestAttribute DynamicRequest request) {
        return crmFegin.delDynamicInfo(request);
    }



    @PostMapping("dynamicShardRecords")
    @ApiOperation(value = "文章分享记录")
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = DynamicRequest.class)
    public ResultModel<List<DynamicShardRecordResponse>> dynamicShardRecords(@RequestAttribute DynamicRequest request){
        log.info("文章分享记录 dynamicShardRecords 请求: {}", JSON.toJSONString(request));
        return crmFegin.dynamicShardRecords(request);
    }

    @PostMapping("dynamicShardRecordDetail")
    @ApiOperation(value = "文章分享详情")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "dynamicId", value = "文章、动态ID", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = DynamicRequest.class)
    public ResultModel<List<ShareRecordModel>> dynamicShardRecordDetail(@RequestAttribute DynamicRequest request){
        return crmFegin.dynamicShardRecordDetails(request);
    }

    @PostMapping("getDynamicPoster")
    @ApiOperation(value = "分享文章海报")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "dynamicId", value = "文章id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = DynamicRequest.class)
    public ResultModel getDynamicPoster(@RequestAttribute DynamicRequest request) {
        return crmFegin.getDynamicPoster(request);
    }


    @PostMapping("selectWebsiteInfo")
    @ApiOperation(value = "查询公司官网信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,paramClass = WebsiteRequest.class)
    public ResultModel selectWebsiteInfo(@RequestAttribute WebsiteRequest request) {

        return crmFegin.selectWebsiteInfo(request);
    }

    @PostMapping("selectDemand")
    @ApiOperation(value = "查询公司官网表单提交信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,paramClass = DemandRequest.class)
    public ResultModel selectDemand(@RequestAttribute DemandRequest request) {

        return crmFegin.selectDemand(request);
    }

    @PostMapping("addWebsiteInfo")
    @ApiOperation(value = "添加/修改公司官网信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "websiteId", value = "官网id", paramType = "Integer"),
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "photos", value = "官网图片(轮播图，逗号隔开)", paramType = "String"),
            @ApiImplicitParam(name = "companyIntroduce", value = "公司介绍", paramType = "String"),
            @ApiImplicitParam(name = "goodsIntroduce", value = "产品介绍", paramType = "String"),
            @ApiImplicitParam(name = "videoUrl", value = "视频介绍地址", paramType = "String"),
            @ApiImplicitParam(name = "phone", value = "公司电话", paramType = "String"),
            @ApiImplicitParam(name = "address", value = "公司地址", paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = WebsiteRequest.class)
    public ResultModel addWebsiteInfo(@RequestAttribute WebsiteRequest request) {

        return crmFegin.addWebsiteInfo(request);
    }

    @PostMapping("insertCompanyVideo")
    @ApiOperation(value = "添加公司視頻")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "公司视频id", paramType = "Integer"),
            @ApiImplicitParam(name = "url", value = "公司视频路径", required = true, paramType = "String"),
            @ApiImplicitParam(name = "describes", value = "公司视频描述", required = true, paramType = "String"),
            @ApiImplicitParam(name = "cover", value = "封面", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true, company=true, isBoss = true, paramClass = CompanyVideoRequest.class)
    public ResultModel<Boolean> insertCompanyVideo(@RequestAttribute CompanyVideoRequest request) {

        return crmFegin.insertCompanyVideo(request);
    }

    @PostMapping("delCompanyVideo")
    @ApiOperation(value = "删除公司視頻")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "公司视频id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, company=true, isBoss = true, paramClass = CompanyVideoRequest.class)
    public ResultModel<Boolean> delCompanyVideo(@RequestAttribute CompanyVideoRequest request) {

        return crmFegin.delCompanyVideo(request);
    }

    @PostMapping("moveCompanyVideo")
    @ApiOperation(value = "上下移动公司视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "公司视频id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "type", value = "1上移，2下移", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, company=true, isBoss = true, paramClass = CompanyVideoRequest.class)
    public ResultModel<Boolean> moveCompanyVideo(@RequestAttribute CompanyVideoRequest request) {

        return crmFegin.moveCompanyVideo(request);
    }

    @PostMapping("selectCompanyRecruit")
    @ApiOperation(value = "查询公司招聘信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,paramClass = CompanyRecruitRequest.class)
    public ResultModel<List<CompanyRecruitResponse>> selectCompanyRecruit(@RequestAttribute CompanyRecruitRequest request) {

        return crmFegin.selectCompanyRecruit(request);
    }

    @PostMapping("addCompanyRecruit")
    @ApiOperation(value = "添加/修改公司招聘信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recruitId", value = "招聘id", paramType = "Integer"),
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "position", value = "职位", paramType = "String"),
            @ApiImplicitParam(name = "recruitAddress", value = "招聘地址", paramType = "String"),
            @ApiImplicitParam(name = "experience", value = "1:应届，2:1年内,3:1-3年,4:3-5年,5:5-10年,6:10年以上,7:全部", paramType = "Integer"),
            @ApiImplicitParam(name = "education", value = "1:全部,2:初中以下,3:中专/中技,4:高中,5:大专,6:本科,7:硕士,8:博士", paramType = "Integer"),
            @ApiImplicitParam(name = "maxSalary", value = "最大薪资", paramType = "Integer"),
            @ApiImplicitParam(name = "minSalary", value = "最小薪资", paramType = "Integer"),
            @ApiImplicitParam(name = "requirement", value = "要求", paramType = "String"),
            @ApiImplicitParam(name = "state", value = "1:招聘中,2:招聘结束", paramType = "Integer"),
            @ApiImplicitParam(name = "accuracy", value = "精度", paramType = "String"),
            @ApiImplicitParam(name = "dimension", value = "维度", paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = CompanyRecruitRequest.class)
    public ResultModel addCompanyRecruit(@RequestAttribute CompanyRecruitRequest request) {

        return crmFegin.addCompanyRecruit(request);
    }

    @PostMapping("addHrPhone")
    @ApiOperation(value = "添加招聘HR电话")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "recruitPhone", value = "企业招聘电话", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = CompanyRequest.class)
    public ResultModel addHrPhone(@RequestAttribute CompanyRequest request) {

        return crmFegin.addHrPhone(request);
    }

    @PostMapping("delCompanyRecruit")
    @ApiOperation(value = "删除公司招聘信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recruitId", value = "企业招聘id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company=true,isBoss = true,paramClass = CompanyRecruitRequest.class)
    public ResultModel delCompanyRecruit(@RequestAttribute CompanyRecruitRequest request) {

        return crmFegin.delCompanyRecruit(request);
    }

    @PostMapping("invitePoster")
    @ApiOperation(value = "获取企业邀请码")
    @ApiController(isLogin = true,card = true,paramClass = CompanyRequest.class)
    public ResultModel<String> invitePoster(@RequestAttribute CompanyRequest request){
        return crmFegin.invitePoster(request);
    }




}
